package com.bw.day03.order

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.bw.base.net.mvvm.BaseFragment
import com.bw.day03.R
import com.bw.day03.adapter.OrderAdapter
import com.bw.day03.databinding.FragmentOrder1Binding
import com.bw.day03.databinding.FragmentOrder2Binding

class Order2Fragment : BaseFragment<FragmentOrder2Binding, OrderViewModel>(){
    lateinit var orderAdapter: OrderAdapter
    override fun initView() {
        orderAdapter= OrderAdapter()
        binding.rv.adapter=orderAdapter
        binding.rv.layoutManager= LinearLayoutManager(context)
        viewModel.order("1",10,1)
    }

    override fun initData() {
        viewModel.orderSuccess.observe(this){
            if (it.code==200){
                orderAdapter.data.clear()
                orderAdapter.data.addAll(it.data.list)
                orderAdapter.notifyDataSetChanged()
            }
        }

    }


    override fun getViewModel(): Class<OrderViewModel> = OrderViewModel::class.java

    override fun getLayoutId(): Int =  R.layout.fragment_order2

}